<template>
  <section class="news-detail-content">
    <!-- 头部导航栏 -->
    <HeaderCom />
    <div class="content-page" id="page">
      <div class="main" v-loading="loading">
        <el-breadcrumb
          separator-class="el-icon-arrow-right"
          class="steps-content"
        >
          <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item @click.native="$router.go(-1)">新闻列表</el-breadcrumb-item>
          <el-breadcrumb-item class="last-bread"
            >新闻列表详情</el-breadcrumb-item
          >
        </el-breadcrumb>
        <!-- <el-button @click="$router.go(-1)" size="small" style="margin-bottom: 10px">返回</el-button> -->
        <p class="top-title">{{ newsInfo.title }}</p>
        <p class="top-subtitle">{{ newsInfo.remark }}</p>
        <p class="top-tip">
          <span>发布时间: </span>
          <span>{{ newsInfo.releaseTime }}</span>
        </p>
        <el-divider></el-divider>
        <div
          class="contentRow"
          v-if="newsInfo.detail"
          v-html="newsInfo.detail.replace(/\n/gm, '<br>')"
        ></div>
        <div class="video" v-if="newsInfo.videoUrl">
          <vueVideoPlayer :src="newsInfo.videoUrl"></vueVideoPlayer>
        </div>
      </div>
    </div>
    <div class="mobile-news-detail">
      <div class="detail-main" v-loading="loading">
        <p class="detail-top-title">{{ newsInfo.title }}</p>
        <p class="detail-top-subtitle">{{ newsInfo.remark }}</p>
        <p class="detail-top-tip">
          <span>发布时间: </span>
          <span>{{ newsInfo.releaseTime }}</span>
        </p>
        <div
          class="detail-contentRow"
          v-if="newsInfo.detail"
          v-html="newsInfo.detail.replace(/\n/gm, '<br>')"
        ></div>
        <div class="detail-video" v-if="newsInfo.videoUrl">
          <vueVideoPlayer :src="newsInfo.videoUrl"></vueVideoPlayer>
        </div>
      </div>
    </div>
    <FooterMenu />
  </section>
</template>
<script>
import FooterMenu from "@/components/footerMenu/index.vue";
import HeaderCom from "@/components/header";
import vueVideoPlayer from "@/components/videoPlayer/videoPlayer.vue";
import {
  getStudentNewsStudyInfoById,
} from "@/request/api";
import { formatTime } from "@/utils/utils";
export default {
  // 组件名称
  name: "studentStyleDetails",
  // 组件参数 接收来自父组件的数据
  props: {},
  // 局部注册的组件
  components: { HeaderCom, vueVideoPlayer, FooterMenu },
  // 组件状态值
  data() {
    return {
      newsInfo: {},
      total: 0,
      pageIndex: 0,
      loading: false,
      studentId: null,
    };
  },
  created() {
    this.getDetail();
  },
  // 组件方法
  methods: {
    async getDetail() {
      const id = this.$route.query.id;
      const { code, data } = await getStudentNewsStudyInfoById({ id });
      if (code !== 0) {
        this.newsInfo = {};
        return;
      }
      if (Number(data.status) !== 1){
        this.$router.replace({name: 'newsAction'})
        this.$message.warning('该内容无法查看，请联系平台管理员～')
      }
      this.newsInfo = {
        ...data,
        releaseTime: formatTime(new Date(data.releaseTime))
      };
    },
  },
  updated() {
    document.getElementById("page").scrollIntoView(true);
  },
};
</script>
<style lang="less">
.news-detail-content {
  .last-bread {
    .el-breadcrumb__inner {
      color: #3d6cb0 !important;
    }
  }
}
</style>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less" scoped>
.news-detail-content {
  position: relative;
  width: 100%;
  background: #f5f8fa;
}
.content-page {
  position: relative;
  width: 1200px;
  margin: 0 auto;
  padding: 80px 0 0;

  .main {
    background: #fff;
    padding: 23px 30px 50px;
    display: flex;
    flex-direction: column;
    align-items: center;

    .steps-content {
      margin: 0 0 20px;
      padding: 0 30px;
      font-size: 15px;
      width: 100%;
    }
    .top-title {
      font-size: 26px;
      font-family: PingFangSC-Semibold, PingFang SC;
      font-weight: 600;
      color: #37383d;
      line-height: 42px;
      margin-bottom: 10px;
      font-weight: 500;
    }
    .top-subtitle {
      color: #666;
      line-height: 37px;
      margin-bottom: 14px;
      font-size: 20px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #9597a0;
      line-height: 28px;
      padding: 0 30px;
      -webkit-line-clamp: 1;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      overflow: hidden;
      text-overflow: ellipsis;
      text-align: left;
    }
    .top-tip {
      font-size: 18px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #9597a0;
      line-height: 25px;
    }
    .list {
      display: flex;
      justify-content: space-between;
      margin-bottom: 34px;
      .list-item {
        .item-title {
          font-size: 23px;
          font-weight: 500;
          color: #0c0c0c;
          line-height: 32px;
          margin-bottom: 20px;
        }
        .item-test {
          font-size: 23px;
          font-weight: 400;
          color: #0c0c0c;
          line-height: 32px;
          margin-bottom: 42px;
        }
      }
      .list-img {
        width: 464px;
        height: 298px;
      }
    }
    .video {
      width: 632px;
      height: 365px;
      margin: 30px auto 0;
      position: relative;
      .video-img {
        width: 100%;
        height: 100%;
      }
      .video-btn {
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 40%);
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        margin: auto;
        display: flex;
        align-items: center;
        justify-content: center;
        .btn-img {
          width: 87px;
          height: 87px;
        }
      }
    }
    .bottom-nav {
      margin-top: 80px;
      display: flex;
      justify-content: space-between;
      color: #2f8efe;
      .el-icon-arrow-left {
        margin-right: 10px;
      }
      .el-icon-arrow-right,
      .el-icon-arrow-down {
        margin-left: 10px;
      }
      .nav-item {
        position: relative;
        font-size: 18px;
        font-weight: 500;
        color: #2f8efe;
        line-height: 33px;
        cursor: pointer;
        &.disabled {
          color: #999;
          cursor: no-drop;
        }
      }
    }
    /deep/ .contentRow {
      position: relative;
      word-break: break-all;
      word-wrap: break-word;
      img {
        max-width: 100%;
      }
    }
  }
}
.student-selecte {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  background: #fff;
  overflow-y: scroll;
  .student-item {
    position: relative;
    display: block;
    width: 100%;
    font-size: 18px;
    padding: 0 20px;
    position: relative;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #606266;
    height: 34px;
    line-height: 34px;
    box-sizing: border-box;
    cursor: pointer;
  }
  .student-item:hover {
    background-color: #f5f7fa;
  }
}

@media (min-width: 769px) {
  .mobile-news-detail {
    display: none;
  }
}
@media (max-width: 768px) {
  .header-com,
  bannerBox,
  .content-page,
  .container {
    display: none;
  }
  .mobile-news-detail {
    display: block;
    background-color: #FFFFFF;
  }
  .detail-main {
    font-size: 0.12rem;
    color: #9597a0;
    line-height: 0.17rem;
    padding: 0.54rem 0.1rem 0.44rem;
    p {
      text-align: center;
    }
    .detail-top-title {
      font-size: 0.15rem;
      font-weight: 600;
      color: #37383d;
      line-height: 0.21rem;
      padding: 0.2rem 0 0.12rem;
    }
    .detail-top-subtitle {}
    .detail-top-tip {
      padding: 0.12rem 0;
      border-bottom: 1px solid rgba(230, 230, 230, 0.6);
    }
    /deep/ .detail-contentRow {
      padding-top: 0.15rem;
      width: 100%;
      overflow: hidden;
      img {
        width: 100%;
        height: auto;
      }
    }
    /deep/ .detail-video {
      width: 3.55rem;
      height: auto;
    }
  }
}
</style>
